// components/bind-phone/index.js
import api from '../../utils/api'
import CONFIG from "../../utils/config";

const app = getApp()

Component({
    properties: {
        datalist: {
            type: [Boolean, Array],
            value: false
        },
        dividerWidth: {
            type: String,
            value: '100%'
        }
    },
    options: {
        addGlobalClass: true
    },
    data: {
        goodsList: []
    },
    lifetimes: {
        attached() {
            this.getGoodsList()
        }
    },
    methods: {
        getGoodsList() {
            if (this.data.datalist && Array.isArray(this.data.datalist)) {
                console.log(this.data.datalist)
                this.setData({
                    goodsList: this.data.datalist
                })
                return
            }
            api.post(`/api/billboard/search/${CONFIG.orgCode}`, {
                data: {
                    type: 'goods',
                    kind: '',
                    name: ''
                },
                head: {
                    firstresult: 1,
                    maxresults: 10
                }
            }).then(res => {
                console.log(res)
                this.setData({
                    goodsList: res
                })
            }).catch(e => {
                console.log(e)
            })
        },
    }
})
